const express = require('express')

const bookRouter = require('./routers/bookRouter')

const db = require('./db');

db(
    ()=>{
        console.log('连接数据库成功');


        //创建应用对象
        const app = express()
        // 使用中间件:静态资源,bodyParser,路由器
        app.use(express.static('public'))
        app.use(express.urlencoded({extended:false}))
        app.use(express.json())
        app.use('/book',bookRouter)


        app.set('view engine', 'ejs')
        app.set('views','./views')

        app.listen('3007',()=>{
            console.log('服务器启动成功:http://localhost:3007');
        })
    },
    ()=>{
        console.log('连接数据库失败');
    }
    
)

